
import static org.junit.Assert.*;
import org.junit.Test;

public class ParseLineTest {
	
	@Test
	public void testParseStartLine() {
		String validStartLine = "Altest1	Start	0	";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should Altest1", "Altest1", testLabel);
		assertEquals("Instruction Should be Start", "Start", testInstruction);
		assertEquals("Operand Should be 0", "0", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseUsing() {
		String validStartLine = "	USING	";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be USING", "USING", testInstruction);
		assertEquals("Operand Should be null", null, testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseStarInstruction() {
		String validStartLine = "	LD-BR	*	:	Use current memory address";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be LD-BR", "LD-BR", testInstruction);
		assertEquals("Operand Should be *", "*", testOperand);
		assertEquals("Comment Should be :	Use current memory address" , ":	Use current memory address", testComment);
	}
	
	@Test
	public void testParseNumberLiteral() {
		String validStartLine = "	ld-ac =0";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be =0", "=0", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseBigNumberLiteral() {
		String validStartLine = "	ld-ac =654654654654";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be =654654654654", "=654654654654", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseBigNegativeNumberLiteral() {
		String validStartLine = "	ld-ac =-654654654321";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be =-654654654321", "=-654654654321", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseOneCharacterLiteralLeftJustifiedOneSpace() {
		String validStartLine = "	ld-ac ='a '";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be ='a '", "='a '", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseOneCharacterLiteralLeftJustifiedTwoSpaces() {
		String validStartLine = "	ld-ac ='a  '";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be ='a  '", "='a  '", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseOneCharacterLiteralRightJustifiedOneSpace() {
		String validStartLine = "	ld-ac =' a'";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be =' a'", "=' a'", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseOneCharacterLiteralRightJustifiedTwoSpaces() {
		String validStartLine = "	ld-ac ='  a'";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be ='  a'", "='  a'", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseOneCharacterLiteralNoSpace() {
		String validStartLine = "	ld-ac ='a'";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be ='a'", "='a'", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	} 
	
	@Test
	public void testParseTwoCharacterLiteralLeftJustifiedOneSpace() {
		String validStartLine = "	ld-ac ='ab '";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be ='ab '", "='ab '", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseTwoCharacterLiteralRightJustifiedOneSpace() {
		String validStartLine = "	ld-ac =' ab'";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be =' ab'", "=' ab'", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseTwoCharacterLiteralSpaceInMiddle() {
		String validStartLine = "	ld-ac ='a b'";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be ='a b'", "='a b'", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseTwoCharacterLiteralNoSpace() {
		String validStartLine = "	ld-ac ='ab'";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be ='ab'", "='ab'", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
	
	@Test
	public void testParseThreeCharacterLiteral() {
		String validStartLine = "	ld-ac ='abc'";
		ParseLine testLine = new ParseLine(validStartLine);
		
		String testLabel = testLine.label();
		String testInstruction = testLine.instruction();
		String testOperand = testLine.operand();
		String testComment = testLine.comment();
		
		assertEquals("Label Should null", null, testLabel);
		assertEquals("Instruction Should be ld-ac", "ld-ac", testInstruction);
		assertEquals("Operand Should be ='abc'", "='abc'", testOperand);
		assertEquals("Comment Should be null" , null, testComment);
	}
}
